package com.example.springboottest.example.enumtest;

import com.example.springboottest.bigdecimal.BigDecimalUtil;

import java.math.BigDecimal;
import java.util.function.DoubleBinaryOperator;

public enum OperationV4 {
    PLUS("+", BigDecimalUtil::add),
    MINUS("-", (x, y) -> BigDecimal.valueOf(x).subtract(BigDecimal.valueOf(y)).doubleValue()
    ),
    TIMES("*", (x, y) -> {
        BigDecimal b1 = BigDecimal.valueOf(x);
        BigDecimal b2 = BigDecimal.valueOf(y);
        return b1.multiply(b2).doubleValue();
    }),
    DIVIDE("/", BigDecimalUtil::div);

    private final String symbol;
    private final DoubleBinaryOperator op;

    OperationV4(String symbol, DoubleBinaryOperator op) {
        this.symbol = symbol;
        this.op = op;
    }

    public double apply(double x, double y) {
        return op.applyAsDouble(x, y);
    }
}
